<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function fn(N,M){
            return Math.floor(Math.random()*(M-N+1))+N
        }
        let sj = fn(1,10)
        let count = 0
        for(let i=3;i>=1;i--){
            let num = +prompt(`输入一个数字,你有${i}次机会`)
            if(num>sj){
                alert(`猜大了,你还有${i-1}机会`)
                count++
            }
            else if(num<sj){
                alert(`猜小了,你还有${i-1}机会`)
                count++
            }
            else if(num===sj){
                alert('你猜对了')
                break
            }
        }
        if(count===3){
            alert(`很遗憾，你已经猜错了3次，游戏结束。正确答案是:${sj}`)
        }
    </script>
</body>
</html>